home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / fractal / kaos.lha / execlib / exec_p_go_proc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  3.9 KB  |  146 lines

  1. /*
  2. ### Execute an external executable and pipe the output to the proper winow ###
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <suntool/sunview.h>
  7. #include <suntool/textsw.h>
  8. #include <suntool/panel.h>
  9. #include <sunwindow/notify.h>
  10.  
  11. int childpid,fromchild,tochild;
  12. FILE *fp_fromchild,*fp_tochild;
  13.  
  14. void exec_panel_go_proc()
  15. {
  16.     static Notify_value exec_pipe_reader(),exec_dead_child();
  17.  
  18.     int i;
  19.     extern int save_option;
  20.     extern char string[],lstring[],exec_dir_name[],exec_file_name[],exec_input_name[];
  21.     extern Textsw exec_textsw;
  22.     extern Panel_item exec_panel_go_item;
  23.     
  24.     all_reset();
  25.  
  26.     if(save_option==0){
  27.         system_mess_proc(1,"Change the save option to either 2-D data or Full data.");
  28.         return;
  29.     }
  30.  
  31.         sprintf(string,"%s/%s",exec_dir_name,exec_input_name);
  32.     textsw_store_file(exec_textsw,string,0,0);
  33.         sprintf(string,"%s/%s < %s/%s",exec_dir_name,exec_file_name,exec_dir_name,exec_input_name);
  34.  
  35.     (void) decode_input_string(lstring,string);
  36.     printf("%s\n",lstring);
  37.     (void) pipe_create(lstring,&childpid,&fromchild,&tochild);
  38.  
  39.     /* Register input and wait3 functions to the notifier */
  40.         (void) notify_set_input_func(exec_panel_go_item,exec_pipe_reader,fromchild);
  41.         (void) notify_set_wait3_func(exec_panel_go_item,exec_dead_child,childpid);
  42. }
  43. /*
  44. ### Read the input pending on the pipe ###
  45. */ 
  46.  
  47. static Notify_value exec_pipe_reader(item,fd)
  48. Panel_item item;
  49. int fd;
  50. {
  51.     int i,result,save_option_old,lock_interval_old;
  52.     extern int save_option,region_index,lock_interval;
  53.     extern int aux_max;
  54.     extern int *aux_on,*aux_win_mode;
  55.     extern char exec_file_name[],error_mess[],error_yes[],error_no[];
  56.     extern FILE *fp_fromchild;
  57.  
  58.     lock_interval_old = lock_interval;
  59.     lock_interval = 0;
  60.     if(region_index==2){
  61.         /* aux_win_i runs from 0 to aux_max-1 */
  62.         /* Count the number of open auxiliary windows */
  63.         for(i=0;i<aux_max;i++){
  64.             if(!aux_on[i]){
  65.                 /* Turn on aux_win_mode of chosed aux window */
  66.                 aux_win_mode[i]=1;
  67.  
  68.                 /* Create_aux_window turns on aux_on */
  69.                 (void) create_aux_windows(i);
  70.  
  71.                 /* Load data from a file pointer fp_fromchild
  72.                 This does the displaying and recording, too.  */
  73.                 load_data(fp_fromchild);
  74.  
  75.                 /* Refresh the panel items of aux panel */
  76.                 all_refresh();
  77.                 return(NOTIFY_DONE);
  78.             }
  79.         }
  80.         /* All the auxiliary windows are used up. Take over one. */
  81.         for(i=0;i<aux_max;i++){
  82.  
  83.             if(i==0){
  84.                 sprintf(error_mess,"No more aux windows. Take over aux_win[%d]?",i);
  85.                 sprintf(error_yes,"Confirm");
  86.                 if(i != aux_max-1){
  87.                     sprintf(error_no,"No. Move to next aux_win[%d]",i+1);
  88.                 }
  89.                 else {
  90.                     sprintf(error_no,"");
  91.                 }
  92.             }
  93.             else if(i<aux_max-1){
  94.                 sprintf(error_mess,"How about this aux_win[%d]?",i);
  95.                 sprintf(error_yes,"Confirm");
  96.                 sprintf(error_no,"Nope. Next!");
  97.             }
  98.             else {
  99.                 sprintf(error_mess,"This is the last chance. Do you want get aux_win[i]?",i);
  100.                 sprintf(error_yes,"Confirm");
  101.                 sprintf(error_no,"Cancel. Exit!");
  102.             }
  103.             result = (int) error_mess_proc(error_mess,error_yes,error_no);
  104.             if(result){
  105.                 /* Turn on aux_win_mode of chosed aux window */
  106.                 aux_win_mode[i]=1;
  107.                 (void) destroy_aux_windows(i);
  108.                 /* Create_aux_window turns on aux_on */
  109.                 (void) create_aux_windows(i);
  110.  
  111.                 /* Load data from a file pointer fp_fromchild
  112.                 This does the displaying and recording, too.  */
  113.                 load_data(fp_fromchild);
  114.  
  115.                 /* Refresh the panel items of aux panel */
  116.                 all_refresh();
  117.                 return(NOTIFY_DONE);
  118.             }
  119.         }
  120.     }
  121.     else {
  122.         /* Load_data may change the save option */
  123.         save_option_old = save_option;
  124.         load_data(fp_fromchild);
  125.         all_refresh();
  126.         save_option = save_option_old;
  127.     }
  128.     lock_interval = lock_interval_old;
  129.     return(NOTIFY_DONE);
  130. }
  131. /*
  132. ### Close the pipe and let the notifier know if the child process died ###
  133. */
  134.  
  135. static Notify_value exec_dead_child(item,pid,status,rusage)
  136. Panel_item item;
  137. int     pid;
  138. union wait *status;
  139. struct rusage *rusage;
  140. {
  141.     extern int fromchild;
  142.         (void) notify_set_input_func(item,NOTIFY_FUNC_NULL,fromchild);
  143.         close(fromchild);
  144.         return(NOTIFY_DONE);
  145. }
  146.